//
// Created by PC on 2024/7/12.
//


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int t, m;
    string n, a;
    cin >> t;
    for (int i = 0; i < t; ++i)
    {
        cin >> n >> m;
        vector<string> l;
        for (char k : n)
        {
            if (k - '0' + 5 < 10)
            {
                a.push_back(k - '0' + 5 + '0');
                l.push_back(a);
                a = "";
            } else
            {
                a = "1";
                l.push_back(a);
                a = "";
                a.push_back(k - '0' - 5 + '0');
                l.push_back(a);
                a = "";
            }
        }
        for (int k = 0; k < l.size(); ++k)
        {
            a += l[k];
        }
        for (int j = 0; j < m - 1; ++j)
        {
            a = "";
            for (int k = 0; k < l.size(); ++k)
            {
                char lk = l[k][0];
                if (l[k].size() == 1 && lk - '0' + 5 < 10)
                {
                    l[k][0] = (lk - '0' + 5 + '0');
                } else
                {
                    l[k] = "1";
                    l[k].push_back(lk - '0' - 5 + '0');
                }
            }
            for (int k = 0; k < l.size(); ++k)
            {
                a += l[k];
            }
            l = {};
            for (int k = 0; k < a.size(); ++k)
            {
                l.push_back(to_string(a[k] - '0'));
            }
        }
//        for (char k : a)
//        {
//            cout << k;
//        }
        cout << a.size() << endl;
        a = "";
    }
    return 0;
}